{extend name="$base" /}
{block name="resources"}
<style>
.modal-infp-style{width:90%;margin:10px auto;}
.modal-infp-style table{width:100%;}
.modal-infp-style table tr td{border: 1px solid #e5e5e5;padding: 10px;}
.align_left{text-align: left;}
.align_right{text-align: right;}
</style>
{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th width="20%" style="text-align:left;"><button class="btn-common btn-small" onclick="save_custom();" style="margin:0 5px 0 0 !important;">添加表单</button></th>
	</tr>
</table>
<table class="table-class">
		<colgroup>
		<col style="width: 2%;">
		<col style="width: 20%;">
		<col style="width: 20%;">
		<col style="width: 30%;">
		<col style="width: 30%;">
		</colgroup>
	<thead>
		<tr align="center">
			<th>
				<!-- <i class="checkbox-common"><input type="checkbox" ></i> -->
			</th>
			<th class="align_left">表单名称<span class="row-20"></th>
			<th class="align_right">表单别名<span class="row-20"></th>
			<th class="align_right">创建时间<span class="row-20"></th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody></tbody>
</table>


<!-- 表单弹框 -->
<div class="modal fade hide" id="order_custom" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<ul class="account_ul">
					<li class="account_active">
						<h3>添加表单</h3>
					</li>
				</ul>
			</div>
			<div class="account-point">
				<div class="modal-body">
					<div class="modal-infp-style">
						<table>
							<tr>
								<td>表单名称</td>
								<td colspan='3'>
									<input type="text" id="oc_name" class="input-common">
								</td>
							</tr>
							<tr>
								<td>表单别名</td>
								<td colspan='3'><input type="text" id="name_alias" class="input-common">
								</td>
								
							</tr>
						</table>
						
					</div>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="oc_id" />
					<button class="btn-common btn-big" onclick="addCustom()">保存</button>
					<button class="btn-common-cancle btn-big" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</div>

{/block}
{block name="script"}
<script type="text/javascript">
function save_custom(oc_id = ''){
	$("#oc_id").val(oc_id);
	$("#order_custom").modal("show");
}

function addCustom(){
	var oc_name = $("#oc_name").val();
	var name_alias = $("#name_alias").val();
	var oc_id = $("#oc_id").val();
	if(oc_name == ""){
		showMessage('error', '表单名称不能为空！');
		return;
	}
	if(name_alias == ""){
		showMessage('error', '表单别名不能为空！');
		return;
	}
	
	$.ajax({
		type : "post",
		url : "{:__URL('__URL__/nsCustomForm/ADMIN_MODULE/config/saveCustom')}",
		data : {
			"oc_name" : oc_name,
			"name_alias" : name_alias,
			"oc_id" : oc_id
		},
		success : function(data){
			if(data > 0){
				showMessage('success', "保存成功");
				$("#order_custom").modal("hide");
				LoadingInfo();
			}else if(data == -2){
				showMessage('error', "表单别名已存在！");
				$("#order_custom").modal("hide");
			}else{
				showMessage('error', "保存失败！");
				$("#order_custom").modal("hide");
			}
		}
	})
}

function LoadingInfo() {
	$.ajax({
		type : "post",
		url : "{:__URL('__URL__/nsCustomForm/ADMIN_MODULE/config/getOrderCustomList')}",
		data : {
			
		},
		success : function(data) {
			console.log(data);
			if (data["data"].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data["data"].length; i++) {
					var html = '';
					html += '<tr align="center">';
					// <i class="checkbox-common"><input name="sub" type="checkbox" value="'+ data["data"][i]["coupon_type_id"]+'" ></i>
					html += '<td></td>';
					
					html += '<td class="align_left">' + data["data"][i]["oc_name"] + '</td>';;
					html += '<td class="align_right">' + data["data"][i]["name_alias"] + '<span class="row-20"></td>';
					html += '<td class="align_right">'+ timeStampTurnTime(data["data"][i]["create_time"]) +'<span class="row-20"></td>';

					html += '<td><a onclick="save_custom('+ data['data'][i]['oc_id'] +')">修改</a>';					
					html += '<a href="'+ __URL(__URL('nsCustomForm/ADMIN_MODULE/config/customDataList?oc_id='+data["data"][i]["oc_id"])) +'">添加自定义字段</a>';
					html += '<a href="javascript:;" onclick="deleteOrderCoupon('+data["data"][i]["oc_id"]+');">删除</a><br/>';
					html += '</td>';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="9">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
			initPageData(data["page_count"],data['data'].length,data['total_count']);
			$("#pageNumber").html(pagenumShow(jumpNumber,$("#page_count").val(),{$pageshow}));
		}
	});
}

function deleteOrderCoupon(oc_id){
	$.ajax({
		type:"post",
		url : "{:__URL('__URL__/nsCustomForm/ADMIN_MODULE/config/deleteOrderCoupon')}",
		data : { "oc_id" : oc_id},
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', data["message"]);
				LoadingInfo();
			}else{
				showMessage('error', data['message']);
			}
		}
	})
}
</script>
{/block}